﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Dynamic;
using System.Collections.ObjectModel;
using System.Collections;

namespace PersonaLibrary.ViewModel.OrganizationsViewModel
{
    public class ShowAllOrganizations : FilteredCollectionViewModel<DataModel.OrganizationEntity>
    {
        #region Ctor

        public ShowAllOrganizations()
            : base()
        {
            base.FilteredPropertyName = "Name";
            base.FilteredPropertyValue = " ";
            base.OrderPropertyName = "Name";
            base.ItemFilterSource = " АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ".ToList();
            base.SetItemTemplate(new Uri("/../View/FilterItemTemplate.xaml", UriKind.Relative), "OrganizationDetail");
        }

        #endregion
        
        #region Override parent

        public override Func<DataModel.OrganizationEntity, bool> Filter
        {
            get
            {
                if (!string.IsNullOrEmpty(FilteredPropertyName) && FilteredPropertyValue != null)
                {
                    return x => x.GetType().GetProperty(FilteredPropertyName).GetValue(x, null).ToString().ToUpper().StartsWith(FilteredPropertyValue.ToString().ToUpper());
                }
                else return x => true;
            }
        }

        protected override Type RepositoryType
        {
            get { return typeof(DataModel.OrganizationRepository); }
        }

        #endregion
    }
}
